<?php
	if($_SESSION['access']!='0') {
		header("Location: ".HTTP_SERVER.ADMIN_DIR);
		exit;
	}
	
	$msg = "";
	if(isset($_POST['submit']) && $_POST['submit']=='Add') {
		if(trim($_POST['add_cat_name'])!='' && trim($_POST['add_cat_count'])!='') {
			$db->Query("INSERT INTO category(name, description, count) VALUES ('".$_POST['add_cat_name']."', '".$_POST['add_cat_descrip']."', '".$_POST['add_cat_count']."');");
			$add_name = $add_descrip = $add_count = "";
		} else {
			$msg = "<span class='error'>Sorry can't add category if it doesn't have at least a name and a nomination limit.</span>";
			$add_name = $_POST['add_cat_name'];
			$add_descrip = $_POST['add_cat_descrip'];
			$add_count = $_POST['add_cat_count'];
		}
	} else $add_name = $add_descrip = $add_count = "";

	//loop through all members and update their member details if necessary
	$db->Query("SELECT * FROM category;");
	$members = $db->getResults();
	foreach($members as $mem) {
		if($_POST['submit'.$mem[0]]=='Update') {
			$db->Query("UPDATE category SET name='".$_POST['edit_cat_name'.$mem[0]]."', description='".$_POST['edit_cat_descrip'.$mem[0]]."', count='".$_POST['edit_cat_count'.$mem[0]]."' WHERE id='".$mem[0]."';");
			$msg = "<span class='success'>Update Successfull.</div>";
		}
		
		if($_POST['submit'.$mem[0]]=='Delete') {
			$db->Query("DELETE FROM category WHERE id='".$mem[0]."';");
			$msg = "<span class='info'>Delete Successfull.</div>";
		}
		
		if($msg) break;
	}

?>